<!--跳转到发帖界面的链接-->
<script setup>
import {PostUtils} from "@/assets/js/PostUtils";
import {setupMapState} from "@/assets/js/vuexUtils";
import {PostAction} from "@ginstone/nga-api/dist/src/enums/PostAction";
import NgaRouterLink from "@/components/common/link/NgaRouterLink.vue";

const props = defineProps({
  action: {type: String, required: true},
  params: {type: Object, required: true},
  bracket: Boolean,
})

const {currentUid} = setupMapState("Account", ['currentUid']);

const getRoute = (name, params) => {
  const {fid, stid, tid, pid, comment} = params
  const query = {account: currentUid.value}
  switch (name) {
    case PostAction.NEW:
      if (stid) query.stid = stid;
      return {name, params: {id: fid}, query}
    case PostAction.REPLY:
      if (comment) query.comment = 1
      return {name, params: {tid, pid}, query}
    case PostAction.QUOTE:
      return {name, params: {tid, pid}, query}
    case PostAction.MODIFY:
      return {name, params: {tid, pid}, query}
    default:
      throw "非法的操作类型: " + name;
  }
}

</script>

<template>
  <span>
    <el-tooltip placement="top-start">
      <nga-router-link :bracket="bracket" :route="getRoute(action,params)">
        <slot></slot>
      </nga-router-link>

      <template #content>
        <el-link :href="PostUtils.buildOfficialUrl(action,params)" target="_blank" type="primary">官方地址</el-link>
      </template>
    </el-tooltip>
  </span>
</template>

<style scoped>

</style>